uniform extern texture imageTexture;
sampler baseMap = sampler_state
{
	Texture = <imageTexture>;
};
int width;
int height;
struct PS_INPUT
{
   float2 Texcoord : TEXCOORD0;
};
float4 Pixel_Shader_ps_main(PS_INPUT Input) : COLOR0 
{
   float offWidth = 1.0f / width;
   float offHeight = 1.0f / height;
   float4 p20rgba = tex2D(baseMap, Input.Texcoord + float2(-offWidth,  offHeight));
   float4 p21rgba = tex2D(baseMap, Input.Texcoord + float2( 0,    offHeight));
   float4 p22rgba = tex2D(baseMap, Input.Texcoord + float2( offWidth,  offHeight));
   float4 p10rgba = tex2D(baseMap, Input.Texcoord + float2(-offWidth,  0));
   float4 p12rgba = tex2D(baseMap, Input.Texcoord + float2( offWidth,  0));
   float4 p00rgba = tex2D(baseMap, Input.Texcoord + float2(-offWidth, -offHeight));
   float4 p01rgba = tex2D(baseMap, Input.Texcoord + float2( 0,   -offHeight));
   float4 p02rgba = tex2D(baseMap, Input.Texcoord + float2( offWidth, -offHeight));
   float p20 = (p20rgba.r + p20rgba.g + p20rgba.b) / 3;
   float p21 = (p21rgba.r + p21rgba.g + p21rgba.b) / 3;
   float p22 = (p22rgba.r + p22rgba.g + p22rgba.b) / 3;
   float p10 = (p10rgba.r + p10rgba.g + p10rgba.b) / 3;
   float p12 = (p12rgba.r + p12rgba.g + p12rgba.b) / 3;
   float p00 = (p00rgba.r + p00rgba.g + p00rgba.b) / 3;
   float p01 = (p01rgba.r + p01rgba.g + p01rgba.b) / 3;
   float p02 = (p02rgba.r + p02rgba.g + p02rgba.b) / 3;
   float sobelX = p00 + 2 * p10 + p20 - p02 - 2 * p12 - p22;
   float sobelY = p20 + 2 * p21 + p22 - p00 - 2 * p01 - p02;
   float edgeSqr = sqrt(sobelX * sobelX + sobelY * sobelY);
   return edgeSqr; 
}
technique SobelEdgeFilter
{
    pass Pass0
    {        
        PixelShader = compile ps_2_0 Pixel_Shader_ps_main();
    }
}